*************************************************************************
*																		*
*					Campaign Panel Book Chapter 6 - Event Variables		*
*																		*
*************************************************************************	

use "${data}\ZA5704_en_v3-2-0.dta", clear

   
*******************************************************************************
** III.1 Merkel reacted adequately to NSA-affair 
*******************************************************************************

mvdecode kp?_2900?, mv(-99/-1)


foreach welle of numlist 2/7 {  //Evaluation refers to CDU object, therefore 1 for CDU
   foreach partei of numlist 1 {
      gen nsa_handling`partei'`welle' = kp`welle'_2900a
   }
}

//not collected in W1, assumption: constant
gen nsa_handling11 = nsa_handling12

//Value range from 0 to 1
foreach welle of numlist 1/7 {
	foreach partei of numlist 1  {
	replace nsa_handling`partei'`welle'=(nsa_handling`partei'`welle'-1)/4
	}
}

sum nsa_handling1?



*******************************************************************************
** III.5 Middle Finger 
*******************************************************************************

// For all parties other than SPD: prob_mittelfinger = 3 (neutral)

foreach welle of numlist 1/5 {
   foreach partei of numlist 4 {
      gen prob_mittelfinger`partei'`welle' = 3
   }
}


// For SPD in wave 6/7: prob_mittelfinger = evaluation

mvdecode kp?_4031, mv(-99/-1)

foreach welle of numlist 6/7 {
   foreach partei of numlist 4 {
      gen prob_mittelfinger`partei'`welle' = kp`welle'_4031 
	  replace prob_mittelfinger`partei'`welle' = 3 if ///
	     kp`welle'_4030==3 //if not seen 
   }
}

tab prob_mittelfinger46  kp6_4031, m

foreach welle of numlist 1/7 {
	foreach partei of numlist 4 {
	replace prob_mittelfinger`partei'`welle' = ///
		(5-prob_mittelfinger`partei'`welle')/4
	}
}

sum prob_mittelfinger4*


tab prob_mittelfinger46 kp6_4031, m 


*******************************************************************************
** III.5 Paedophilia
*******************************************************************************

mvdecode kp7_4040, mv(-99/-1)

* ATTENTION: CHANGE: paedophilia scandal began before wave 6. The values from
* wave 7 will therefore be transferred to wave 6

// Greens unproblematic until 5

foreach welle of numlist 1/5 {
   foreach partei of numlist 6 {
      gen prob_paed`partei'`welle' = 3
   }
}

// In wave 6 und 7: evaluation

foreach welle of numlist 6 7 {
   foreach partei of numlist 6 {
      gen prob_paed`partei'`welle' = kp7_4040
   }
}


sum prob_paed6?

foreach welle of numlist 1/7 {
	foreach partei of numlist 6 {
	replace prob_paed`partei'`welle'=(prob_paed`partei'`welle'-1)/4
	}
}

tab1 prob_paed6?


*******************************************************************************
** III.5 Veggie-Day 
*******************************************************************************

mvdecode kp?_2940?, mv(-99/-1)


// Veggie-Day: Greens till wave 3 on 3

foreach partei of numlist 6 {
   foreach welle of numlist 1/3 {
      gen veggie`partei'`welle' = 3
}
}


// Waves 4, 6 und 7 question was asked

foreach partei of numlist 6 {
   foreach welle of numlist 4 6 7 {
      gen veggie`partei'`welle' = kp`welle'_2940b
}
}

//in W5 not asked, therefore calculate mean value
egen veggie65 = rowmean(veggie64 veggie66)


foreach welle of numlist 1/7 {
	foreach partei of numlist 6  {
	replace veggie`partei'`welle'=(veggie`partei'`welle'-1)/4
	}
}

sum veggie6?

************************************************************************
** Motorway Toll
************************************************************************


// Toll: Evaluation in 4, 6 and 7

foreach partei of numlist 1 {
   foreach welle of numlist 4 6 7 {
      gen maut`partei'`welle' = kp`welle'_2940a
}
}

egen maut15 = rowmean(maut14 maut16)

// before survey impute value from wave 4 (was already an issue before)
foreach welle of numlist 1/3 {
gen maut1`welle' = maut14
}


//value range
foreach welle of numlist 1/7 {
	foreach partei of numlist 1  {
	replace maut`partei'`welle'=(maut`partei'`welle'-1)/4
	}
}

sum maut1?


*******************************************************************************
** III.1 Merkel reacted adequately to Syria conflict 
*******************************************************************************


mvdecode kp?_2970c, mv(-99/-1)

// Beginning in W5 evaluation was measured

foreach welle of numlist 5/7 {
   foreach partei of numlist 1 {
      gen syria_handling`partei'`welle' = kp`welle'_2970c
   }
}

//before it was not measured but already an issue, therefore replace from W5

foreach welle of numlist 1/4 {
gen syria_handling1`welle' = syria_handling15
}



foreach welle of numlist 1/7 {
	foreach partei of numlist 1 {
	replace syria_handling`partei'`welle'=(syria_handling`partei'`welle'-1)/4
	}
}

sum syria_handling1?


*******************************************************************************
** III.5 Election Arena (Merkel/Steinbrück)
*******************************************************************************

// For all parties besides CDU/CSU: wahlarena_m = 3 (neutral)

// For CDU/CSU and SPD in waves 1-5: wahlarena_m/wahlarena_s = 3 (neutral)

foreach welle of numlist 1/5 {
   foreach partei of numlist 1 4 {
      gen wahlarena`partei'`welle' = 3
}
}



// For CDU/CSU and SPD in waves 6-7: if not seen, otherwise use evaluation

mvdecode kp?_2990?, mv(-99/-1) 

foreach welle of numlist 6/7 {
   foreach partei of numlist 1 {
      gen wahlarena`partei'`welle' = (kp6_2990a-6)*-1
	  replace wahlarena`partei'`welle' = 3 if (kp6_2980a==3)
}
}

foreach welle of numlist 6/7 {
   foreach partei of numlist 4 {
      gen wahlarena`partei'`welle' = (kp6_2990b-6)*-1
	  replace wahlarena`partei'`welle' = 3 if (kp6_2980b==3)
}
}


foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace wahlarena`partei'`welle'=(wahlarena`partei'`welle'-1)/4
	}
}

sum wahlarena*
tab wahlarena46 kp6_2990b, m


*******************************************************************************
** III.5 Credibility Steinbrück Rejection Red/Red/Green 
*******************************************************************************

// For SPD until 2: Credibility == 3

foreach partei of numlist 4 {
   foreach welle of numlist 1/2 {
      gen glaubw_rrg`partei'`welle'=3
   }
}

// For SPD in waves 3,5,6: Credibility == Evaluation

mvdecode kp?_2930, mv(-99/-1)

foreach partei of numlist 4 {
   foreach welle of numlist 3 5 6 {
      gen glaubw_rrg`partei'`welle'=(kp`welle'_2930-6)*-1
   }
}

// not asked in W4, mean from 3 and 5
 egen glaubw_rrg44 = rowmean(glaubw_rrg43 glaubw_rrg45)

 // not asked in w7, impute value from W7
foreach partei of numlist 4 {
   foreach welle of numlist 7 {
      gen glaubw_rrg`partei'`welle' = glaubw_rrg46
   }
}


//Value range
foreach welle of numlist 1/7 {
	foreach partei of numlist 4 {
	replace glaubw_rrg`partei'`welle'=(glaubw_rrg`partei'`welle'-1)/4
	}
}

sum glaubw_rrg??


*******************************************************************************
** III.5 Evaluation Election in Bavaria
*******************************************************************************

foreach welle of numlist 1/5 {
   foreach partei of numlist 5 {
      gen bayern`partei'`welle' = 3
   }
}

foreach welle of numlist 6/7 {
   gen bayern5`welle' = kp6_3220b if kp6_3220b>0
}



foreach welle of numlist 1/7 {
	replace bayern5`welle'=(bayern5`welle'-1)/4
	}

fre bayern5?


**************************************************************************
*			Reception TV-debate yes/no									*
*																		*
**************************************************************************

fre kp?_1800*
* only respondents who did not participate in wave 5 received this question later

* nobody could have seen the debate before wave 5
foreach welle of numlist 1/4 {
gen watcheddebate`welle' = 0 if w`welle'a==1
}

gen watcheddebate5 = 0 if kp5_1800==3
replace watcheddebate5 = 1 if kp5_1800==1 | kp5_1800==2

tab watcheddebate5 kp5_1800

* After the event, insert the same value
* Nach Ereignis, densleben wert einsetzen
gen watcheddebate6 = watcheddebate5
gen watcheddebate7 = watcheddebate6


*************************************************************************
**** Wahlomat used/not used						***********
****************************************************************************

// The party-specific variables are placed at the top. 
// Here only general usage
// General accord/discord with a party would also be interesting, but was not measured

tab1 kp5_3490 kp6_3490 kp7_3490, nolabel
tab kp6_3490 kp5_3490
tab1 kp5_3510 kp6_3510 kp7_3510

foreach welle of numlist 1/7 {
    gen wahlomatg`welle' = 0
   }


foreach welle of numlist 5/7 {
    replace wahlomatg`welle' = 1 if kp5_3490==1 
}  

foreach welle of numlist 6/7 {
    replace wahlomatg`welle' = 1 if kp6_3490==1 
}  

foreach welle in 7 {
    replace wahlomatg`welle' = 1 if kp7_3490==1 
}  



**************************************************************************
***			Reception election arena yes/no 						****
*************************************************************************

tab1 kp?_2980?
tab1 kp?_2980?, nolabel
mvdecode kp?_2980?, mv(-99/-1)

foreach welle of numlist 1/5 {
      gen wahlarenag_mg`welle' = 0
	  gen wahlarenag_sg`welle' = 0
     }
	 
foreach welle of numlist 6 {
    recode kp`welle'_2980a (1 2=1) (3=0) (else=.), gen(wahlarenag_mg`welle')
	recode kp`welle'_2980b (1 2=1) (3=0) (else=.), gen(wahlarenag_sg`welle')
     }
	 	 
gen wahlarenag_mg7=wahlarenag_mg6
gen wahlarenag_sg7=wahlarenag_sg6



*******************************************************************************
** III.3 Save Variables
*******************************************************************************

keep lfdn nsa_handling12-wahlarenag_sg7

save "Data\events13.dta", replace
 